home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / The Hacks! / SloppyWindows / SloppyWindows.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-21  |  2.5 KB  |  123 lines  |  [TEXT/CWIE]

  1.  
  2. #include <A4Stuff.h>
  3. #include <SetUpA4.h>
  4. #include <Traps.h>
  5. #include <MacWindows.h>
  6. #include <QuickDraw.h>
  7. #include <Resources.h>
  8. #include <Sound.h>
  9. #include <LowMem.h>
  10.  
  11. #define SOUND 1
  12.  
  13. typedef pascal OSErr (*PostEventType)(short eventNum:__a0,long eventMsg:__d0):__d0;
  14. PostEventType    oldPostEvent;
  15.  
  16. typedef pascal void (*ProcessMgrDispatchType)(short selector);
  17. ProcessMgrDispatchType oldProcessMgrDispatch;
  18.  
  19. #if SOUND
  20. SndListHandle    sound;
  21. SndChannelPtr    chan;
  22. #endif
  23.  
  24. static pascal OSErr myPostEvent2(short eventNum,long eventMsg)
  25. {
  26.     short    resultCode = noErr;
  27.     Boolean    doIt = true;
  28.     Rect    windowRect;
  29.     
  30.     EnterCallback();
  31.     
  32.     if ( eventNum == mouseDown )
  33.         {
  34.         WindowPeek    frontWindow    = (WindowPeek) LMGetWindowList();
  35.         if ( frontWindow )
  36.             {
  37.             //The following code is dereferencing a handle at interupt time.  This will
  38.             //do bad things for you if you think you can use this code for your own
  39.             //purposes.
  40.             windowRect    = (*frontWindow->strucRgn)->rgnBBox;
  41.              if ( !PtInRect( LMGetRawMouseLocation(), &windowRect ) )
  42.                 {
  43.                 InsetRect( &windowRect, -10, 0 );
  44.                 if ( PtInRect( LMGetRawMouseLocation(), &windowRect ) )
  45.                     {
  46.                     #if SOUND
  47.                     if ( sound && chan )
  48.                         SndPlay( chan, sound, true );
  49.                     else
  50.                         Debugger();
  51.                     #endif
  52.                     doIt = false;
  53.                     }
  54.                 }
  55.             }
  56.         }
  57.  
  58.     if (doIt)
  59.         resultCode    = (oldPostEvent)(eventNum, eventMsg);
  60.     ExitCallback();
  61.     return    resultCode;
  62. }
  63.  
  64. asm static pascal OSErr myPostEvent(short eventNum,long eventMsg)
  65. {
  66.     movem.l d1-d3/a0-a3,-(a7)
  67.     clr.w -(a7)
  68.     move.w a0,-(a7)
  69.     move.l d0,-(a7)
  70.     jsr myPostEvent2
  71.     move.w (a7)+,d0
  72.     movem.l (a7)+,d1-d3/a0-a3
  73.     rts
  74. }
  75.  
  76.  
  77. static pascal void myWatchForProcessMgr(short selector)
  78. {
  79.     ProcessMgrDispatchType localTrapAddress;
  80.     
  81.     EnterCodeResource();
  82.  
  83.     if (selector == 1)
  84.     {
  85.         // install findwindow patch here
  86.         oldPostEvent = (PostEventType)GetOSTrapAddress( _PostEvent );
  87.         SetOSTrapAddress( (UniversalProcPtr)myPostEvent, _PostEvent );
  88.     }
  89.  
  90.     localTrapAddress = oldProcessMgrDispatch;
  91.     ExitCodeResource();
  92.     
  93.     (*oldProcessMgrDispatch)(selector);
  94. }
  95.  
  96. void main( void )
  97. {
  98.     Handle    myHandle;
  99.  
  100.     EnterCodeResource();
  101.     PrepareCallback();
  102.  
  103.     SetZone( SystemZone() );
  104.     myHandle    = Get1Resource( 'INIT', 300 );
  105.     
  106.     
  107.     DetachResource( myHandle );
  108.     HLock( myHandle );
  109.     
  110. #if SOUND
  111.     sound    = (SndListHandle)Get1Resource( 'snd ', 8192 );    
  112.     DetachResource( (Handle)sound );
  113.     HLock((Handle)sound);
  114.     SndNewChannel( &chan, 0, 0, nil );
  115.     SndPlay( chan, sound, true );
  116. #endif
  117.  
  118.     oldProcessMgrDispatch = (ProcessMgrDispatchType)GetToolTrapAddress( 0xABCF );
  119.     SetToolTrapAddress( (UniversalProcPtr)myWatchForProcessMgr, 0xABCF );
  120.     
  121.     ExitCodeResource();
  122. }
  123.